package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.List;

public class LibraryManager {

    List<Book> books;

    public LibraryManager(List<Book> books) {
        this.books = books;
    }

    public void checkOutBook(String title, String patron) {
        Book book = findBook(title);
        if (book != null) {
            book.checkOut(patron);
        } else {
            System.out.println("That is not an available title. Please try again");
        }
    }

    private Book findBook(String title) {
        for (Book book : books) {
            if (book.getTitle().equals(title)) {
                return book;
            }
        }
        return null;
    }

    public void printBooks(PrintStream printStream) {
        for (Book book : books) {
            printStream.println(book.toString());
        }
        printStream.println();
    }
}
